package hlhj.fhp.supreme.activitys

import android.app.Activity
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import fhp.hlhj.giantfold.utils.LogUtil
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.BaseBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import hlhj.fhp.supreme.utils.MyUtils
import kotlinx.android.synthetic.main.activity_add_bank_aty.*

class AddBankAty : BaseAty() {
    val BANKSELECT=1
    private var bankName=""
    private var name=""
    private var bankNum=""
    override fun getContentId(): Int {
        return R.layout.activity_add_bank_aty
    }

    override fun initListener() {

        btExit.setOnClickListener {
            finish()
        }

        loBank.setOnClickListener {
            startActivityForResult(Intent(this,SelectBankAty::class.java),BANKSELECT)
        }

        btCommit.setOnClickListener {
            if (etCardNum.text.toString().isEmpty()||etName.text.toString().isEmpty()||tvBankName.text.toString().isEmpty()){
                MyUtils.toast("请完善信息")
            }else{
                OkGo.post<BaseBean>(Urls.BaseUrl+Urls.ADD_BANK)
                        .params("name",etName.text.toString())
                        .params("bank_name",tvBankName.text.toString())
                        .params("id_card",etCardNum.text.toString())
                        .execute(object :JsonCallBack<BaseBean>(this){
                            override fun onSuccess(response: Response<BaseBean>?) {
                                val bean = response?.body()
                                if (bean?.code==1){
                                    MyUtils.toast("操作成功")
                                    finish()
                                }else{
                                    MyUtils.toast(bean?.msg)
                                }
                            }
                        })
            }

        }
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        LogUtil.log("返回----$resultCode")
        if (resultCode!= Activity.RESULT_OK)return
        if (requestCode==BANKSELECT){
            val bankName = data?.getStringExtra("bankName")
            if (bankName!=null){
                this.bankName=bankName
                tvBankName.text=bankName
            }
        }
    }
}
